﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Drawing;


namespace HA.Data.DisplayOptions2
{
    [Serializable]
    public class DOContour : ContourEventProperty, IObjectDataHelper, ICloneable
    {


        //注意 ：修改字段后 需要修改运算符重载


        public DOContour()
        {
            //取得
            this._contourColors = new List<Color>();
            this._contourColors.Add(Color.Blue);
            this._contourColors.Add(Color.LightBlue);
            this._contourColors.Add(Color.LightGreen);
            this._contourColors.Add(Color.Yellow);
            this._contourColors.Add(Color.Red);
        }


        //[field: NonSerialized]
        //public event EventHandler ContourLinesChanged;




        //[field: NonSerialized]
        //public  bool _isNeedUpdateData = false;




        #region 属性部分


        bool _isUseCellRealData = false;
        /// <summary>
        /// 是否使用单元格的真实数据  默认为false：即根据单元格中心点的data对周围4个点的数据进行插值
        /// 
        /// </summary>
        public bool IsUseCellRealData
        {
            get { return this._isUseCellRealData; }
            set
            {
                if (_isUseCellRealData == value)
                {
                    return;
                }
                else
                {
                    this._isUseCellRealData = value;
                    this.isNeedUpdateData = true;
                }

            }
        
        }




        DOContourLineProperty _contourLineProperty = new DOContourLineProperty();
        /// <summary>
        /// 等值线属性配置参数  包括图例和标注
        /// </summary>
        public DOContourLineProperty ContourLineProperty
        {
            get { return _contourLineProperty; }
            set
            {
                if (_contourLineProperty == value)
                {
                    return;
                }
                else
                {
                    _contourLineProperty = value;
                    this.isNeedUpdateData  = true;
                }
            }
        }



        bool _isSpecifyPrecision = false;
        /// <summary>
        /// 是否使用统一小数点控制  默认false
        /// </summary>
        public bool IsSpecifyPrecision
        {
            get { return _isSpecifyPrecision; }
            set
            {
                if (_isSpecifyPrecision == value)
                {
                    return;
                }
                else
                {
                    _isSpecifyPrecision = value;
                    this.isNeedUpdateData = true;
                }
            }
        }


        //int _precision = 1;

        //public int Precision
        //{
        //    get { return _precision; }
        //    set
        //    {
        //        _precision = value;
        //        if (_precision < 0)
        //        {
        //            _precision = 1;
        //        }
        //        if (_precision > 15)
        //        {
        //            _precision = 1;
        //        }
        //    }
        //}


        //int _decimalDigitNum = 1;
        
        public int DecimalDigitNum
        {
            get
            {
                if (this._isSpecifyPrecision)
                {

                    if (_specifyPrecisioDecimalNum < 0)
                    {
                        _specifyPrecisioDecimalNum = 1;

                    }
                    if (_specifyPrecisioDecimalNum > 15)
                    {
                        _specifyPrecisioDecimalNum = 15;
                    }
                    return _specifyPrecisioDecimalNum;
                }
                else
                {
                    if (this._isUseScientificNotation)
                    {

                        //如果使用了科学计数法 还需要考虑整部部分由于格式化加入小数点中的位数  
                        //要通过整数部分和数据规整时计算的合理小数位数来共同决定科学计数法模式合理的小数位数

                        int maxNumInINT = GetDecimalLengthInDoubleValue(this._contourlines );

                        if (_noSpecifyPrecisionDecimalNum < 0)
                        {
                            _noSpecifyPrecisionDecimalNum = 1;
                        }
                        if (_noSpecifyPrecisionDecimalNum > 6)
                        {
                            _noSpecifyPrecisionDecimalNum = 6;
                        }



                        if ((_noSpecifyPrecisionDecimalNum+maxNumInINT)<0)
                        {
                            return 1;
                        }
                        if ((_noSpecifyPrecisionDecimalNum+maxNumInINT)>6)
                        {
                            return 6;
                        }

                        return (_noSpecifyPrecisionDecimalNum + maxNumInINT);


                    }
                    else
                    {
                        //如果不是使用科学计数法的模式，则只需要考虑规整时由数据计算的小数位数即可

                        if (_noSpecifyPrecisionDecimalNum < 0)
                        {
                            _noSpecifyPrecisionDecimalNum = 1;
                        }
                        if (_noSpecifyPrecisionDecimalNum > 6)
                        {
                            _noSpecifyPrecisionDecimalNum = 6;
                        }
                        return _noSpecifyPrecisionDecimalNum;
                    }
                }

            }

            //get { return _decimalDigitNum; }
            //set
            //{
            //    if (_decimalDigitNum == value)
            //    {
            //        return;
            //    }
            //    else
            //    {
            //        _decimalDigitNum = value;
            //        this.isNeedUpdateData = true;
            //    }

            //    if (_decimalDigitNum < 0)
            //    {
            //        _decimalDigitNum = 1;
            //    }
            //    if (_decimalDigitNum > 15)
            //    {
            //        _decimalDigitNum = 15;
            //    }
            //}
        }



        int _specifyPrecisioDecimalNum = 1;
        /// <summary>
        /// 小数点位数  包括等值线值，等值线标注，图例文本等等
        /// 约定：
        /// 不使用统一小数点位数时：使用最大15位控制
        /// 使用统一小数点位数时：小数点位数读取该属性，最小1位，最大15位
        /// </summary>
        public int SpecifyPrecisioDecimalNum
        {
            get { return _specifyPrecisioDecimalNum; }
            set
            {
                if (_specifyPrecisioDecimalNum == value)
                {
                    return;
                }
                else
                {
                    _specifyPrecisioDecimalNum = value;
                    this.isNeedUpdateData = true;
                }

                if (_specifyPrecisioDecimalNum < 0)
                {
                    _specifyPrecisioDecimalNum = 1;
                }
                if (_specifyPrecisioDecimalNum > 15)
                {
                    _specifyPrecisioDecimalNum = 15;
                }
            }
        }



        int _noSpecifyPrecisionDecimalNum = 6;
        /// <summary>
        /// 小数点位数  包括等值线值，等值线标注，图例文本等等
        /// 约定：
        /// 不使用统一小数点位数时：读取该字段
        /// 使用统一小数点位数时：读取DecimalDigitNum
        /// </summary>
        public int NoSpecifyPrecisionDecimalNum
        {
            //get { return _noSpecifyPrecisionDecimalNum; }
            set
            {

                if (_noSpecifyPrecisionDecimalNum == value)
                {
                    return;
                }
                else
                {
                    _noSpecifyPrecisionDecimalNum = value;
                    this.isNeedUpdateData = true;
                }

                if (_noSpecifyPrecisionDecimalNum < 0)
                {
                    _noSpecifyPrecisionDecimalNum = 1;
                }
                if (_noSpecifyPrecisionDecimalNum > 6)
                {
                    _noSpecifyPrecisionDecimalNum = 6;
                }
            }
        }




        bool _isUseScientificNotation = false;
        /// <summary>
        /// 是否使用科学计数法表示数据
        /// </summary>
        public bool IsUseScientificNotation
        {
            get { return _isUseScientificNotation; }
            set
            {

                if (_isUseScientificNotation == value)
                {
                    return;
                }
                else
                {
                    _isUseScientificNotation = value;
                    this.isNeedUpdateData = true;
                }
            }
        }






        #region ContourMethod

        int _lineWidth = 2;
        /// <summary>
        /// 等值线线条宽度
        /// </summary>
        public int LineWidth
        {
            get { return _lineWidth; }
            set
            {
                if (_lineWidth == value)
                {
                    return;
                }
                else
                {
                    _lineWidth = value;
                    this.isNeedUpdateData = true;
                }
                if (_lineWidth <= 0)
                {
                    _lineWidth = 1;
                }
            }
        }



        Color _lineColor = Color.Black;
        /// <summary>
        /// 等值线线条颜色
        /// </summary>
        public Color LineColor
        {
            get { return _lineColor; }
            set
            {
                if (_lineColor == value)
                {
                    return;
                }
                else
                {
                    _lineColor = value;
                    this.isNeedUpdateData = true;
                }
            }
        }





        ContourDisplayType _contourDisplayType = ContourDisplayType.LinearAndColorFill;
        /// <summary>
        /// ContourOptions中的Contour选项控制   显示模式：线性，填充，线性+填充
        /// </summary>
        public ContourDisplayType ContourType
        {
            get { return _contourDisplayType; }
            set
            {
                if (_contourDisplayType == value)
                {
                    return;
                }
                else
                {
                    _contourDisplayType = value;
                    this.isNeedUpdateData = true;
                }
            }
        }



        ContourColorMode _colorMode;
        /// <summary>
        /// 是否使用  ColorRamp
        /// </summary>
        public ContourColorMode ColorMode
        {
            get { return _colorMode; }
            set
            {
                if (_colorMode == value)
                {
                    return;
                }
                else
                {
                    _colorMode = value;
                    this.isNeedUpdateData = true;
                }
            }
        }
        #endregion


        #region 使用的数据范围  DataRange

        bool _isSpecifyRange = false;
        /// <summary>
        /// 是否使用指定范围？
        /// </summary>
        public bool IsSpecifyRange
        {
            get { return _isSpecifyRange; }
            set
            {
                if (_isSpecifyRange == value)
                {
                    return;
                }
                else
                {
                    _isSpecifyRange = value;
                    this.isNeedUpdateData = true;
                }
            }
        }

        double _spRangeMin = 0;
        public double SpRangeMin
        {
            get { return _spRangeMin; }
            set
            {
                if (_spRangeMin == value)
                {
                    return;
                }
                else
                {
                    _spRangeMin = value;
                    this.isNeedUpdateData = true;
                }
            }
        }

        double _spRangeMax = 1;
        public double SpRangeMax
        {
            get { return _spRangeMax; }
            set
            {
                if (_spRangeMax == value)
                {
                    return;
                }
                else
                {
                    _spRangeMax = value;
                    this.isNeedUpdateData = true;
                }
            }
        }



        double _dsMin = 0;
        /// <summary>
        /// 数据集最小值
        /// </summary>
        public double DsMin
        {
            get { return _dsMin; }
            set
            {
                if (_dsMin == value)
                {
                    return;
                }
                else
                {
                    _dsMin = value;
                    this.isNeedUpdateData = true;
                }
            }
        }

        double _dsMax = 1;
        /// <summary>
        /// 数据集最大值
        /// </summary>
        public double DsMax
        {
            get { return _dsMax; }
            set
            {
                if (_dsMax == value)
                {
                    return;
                }
                else
                {
                    _dsMax = value;
                    this.isNeedUpdateData = true;
                }
            }
        }


        public double Min
        {
            get
            {
                if (this._isSpecifyRange)
                {
                    return this._spRangeMin;
                }
                else
                {
                    return this._dsMin;
                }
            }
        }


        public double Max
        {
            get
            {
                if (this._isSpecifyRange)
                {
                    return this._spRangeMax;
                }
                else
                {
                    return this._dsMax;
                }
            }
        }

        #endregion





        #region ContourInterval

        ContourInterval _contourInterval = ContourInterval.NumberOfContours;
        /// <summary>
        /// 
        /// </summary>
        public ContourInterval ContourInterval
        {
            get { return _contourInterval; }
            set
            {
                if (_contourInterval == value)
                {
                    return;
                }
                else
                {
                    _contourInterval = value;
                    this.isNeedUpdateData = true;
                }
            }
        }




        double dataRange = 1;
        /// <summary>
        /// 数据间距
        /// </summary>
        public double DataRange
        {
            get { return dataRange; }
            set
            {
                if (dataRange == value)
                {
                    return;
                }
                else
                {
                    dataRange = value;
                    this.isNeedUpdateData = true;
                }
                if (dataRange <= 0)
                {
                    dataRange = 1;
                }
            }
        }

        int dataCount = 15;
        /// <summary>
        /// 要生成的等值线个数
        /// </summary>
        public int DataCount
        {
            get { return dataCount; }
            set
            {
                if (dataCount == value)
                {
                    return;
                }
                else
                {
                    dataCount = value;
                    this.isNeedUpdateData = true;
                }
                if (dataCount <= 0)
                {
                    dataCount = 1;
                }
            }
        }




        List<System.Drawing.Color> _contourColors;
        /// <summary>
        /// 颜色集合
        /// </summary>
        public List<System.Drawing.Color> ContourColors
        {
            get { return _contourColors; }
            set
            {

                _contourColors = value;

            }

        }





        #endregion







        double _transparency = 0;
        /// <summary>
        /// 透明度
        /// </summary>
        public double Transparency
        {
            get { return _transparency; }
            set
            {
                if (_transparency == value)
                {
                    return;
                }
                else
                {
                    _transparency = value;
                    this.isNeedUpdateData = true;
                }
            }
        }





        List<LinearContourColorValue> _contourlines = new List<LinearContourColorValue>();
        /// <summary>
        /// 存储的等值线值
        /// </summary>
        public List<LinearContourColorValue> ContourLines
        {
            get { return _contourlines; }

        }


       


        //bool _isShowLegend = false;
        ///// <summary>
        ///// 是否显示图例  该标志放在了子类 ContourLineScalarBar 中
        ///// </summary>
        //public bool IsShowLegend
        //{
        //    get { return _isShowLegend; }
        //    set { _isShowLegend = value; }
        //}

        #endregion



        #region 方法部分

        ///// <summary>
        ///// 用于对话框等的改变事件
        ///// </summary>
        ///// <param name="lines"></param>
        //public void ResetContourLines(List<LinearContourColorValue> lines)
        //{
        //    this._contourlines.Clear();
        //    this._contourlines.AddRange(lines);
        //    if (this.ContourLinesChanged != null)
        //    {
        //        this.ContourLinesChanged(this, new EventArgs());
        //    }
        //}

        //public bool IsDataChanged(DOContourOptionV2 contour)
        //{
        //    return true;
        //}


        /// <summary>
        /// 计算对应的等值线值以及颜色
        /// </summary>
        public void BuildContourlines()
        {
            if (this.dataCount <= 0)
            {
                this.dataCount = 1;
            }
            if (this.dataRange <= 0)
            {
                this.dataRange = 1;
            }

            ContourBuildOption cb = new ContourBuildOption(this.Min, this.Max, this._contourColors);
            List<LinearContourColorValue> lines = new List<LinearContourColorValue>();
            if (this._contourInterval == ContourInterval.NumberOfContours)
            {
                lines = cb.BuildCountourLineWithCount(this.DataCount, this.SpecifyPrecisioDecimalNum, this.IsSpecifyPrecision, ref this._noSpecifyPrecisionDecimalNum );
            }
            else if (this._contourInterval == ContourInterval.SpecifiedInterval)
            {
                lines = cb.BuildContourLineWithDistance(this.DataRange, this.SpecifyPrecisioDecimalNum, this.IsSpecifyPrecision, ref this._noSpecifyPrecisionDecimalNum);
            }
            else if (this._contourInterval == ContourInterval.SpecifiedValues)
            {
                //此处少自定义生成方案
            }



            this._contourlines.Clear();

            this._contourlines.AddRange(lines);


        }

        /// <summary>
        /// 用于对话框编辑了所有的属性
        /// </summary>
        /// <param name="doContour"></param>
        //public void ReSetContourOption(DOContour doContour)
        //{
        //    if (this != doContour)
        //    {
        //        this._colorMode = doContour._colorMode;
        //        this._contourColors = doContour._contourColors;
        //        this._contourDisplayType = doContour._contourDisplayType;
        //        this._contourInterval = doContour._contourInterval;
        //        this._contourlines = doContour._contourlines;
        //        this._dsMax = doContour._dsMax;
        //        this._dsMin = doContour._dsMin;
        //        //this._isShowLegend = doContour._isShowLegend;
        //        this._isSpecifyPrecision = doContour._isSpecifyPrecision;
        //        this._isSpecifyRange = doContour._isSpecifyRange;
        //        //this._precision = doContour._precision;
        //        this._spRangeMax = doContour._spRangeMax;
        //        this._spRangeMin = doContour._spRangeMin;
        //        this._transparency = doContour._transparency;
        //        this.dataRange = doContour.dataRange;
        //        this.dataCount = doContour.dataCount;
        //        //if (this.ContourLinesChanged != null)
        //        //{
        //        //    this.ContourLinesChanged(this, new EventArgs());
        //        //}
        //    }
        //    //需要判断和旧的等值线是否相等
        //}






        #endregion


        public static bool operator ==(DOContour sp1, DOContour sp2)
        {
            // check for both null (cast to object or recursive loop)
            if ((object)sp1 == null && (object)sp2 == null)
            {
                return true;
            }

            // check for either of them == to null
            if (((object)sp1 == null && (object)sp2 != null) || ((object)sp1 != null && (object)sp2 == null))
            {
                return false;
            }

            if (sp1 ._contourLineProperty !=sp2 ._contourLineProperty )
            {
                return false;
            }

            //是否使用单元格的真实数据
            if (sp1.IsUseCellRealData !=sp2.IsUseCellRealData )
            {
                return false;
            }

            //小数点位数
            if (sp1 .DecimalDigitNum !=sp2 .DecimalDigitNum )
            {
                return false;
            }
            if (sp1._specifyPrecisioDecimalNum != sp2._specifyPrecisioDecimalNum)
            {
                return false;
            }
            //if (sp1._decimalDigitNum != sp2._decimalDigitNum)
            //{
            //    return false;
            //}
            if (sp1._noSpecifyPrecisionDecimalNum != sp2._noSpecifyPrecisionDecimalNum)
            {
                return false;
            }
            if (sp1 ._isUseScientificNotation !=sp2._isUseScientificNotation )
            {
                return false;
            }



            if (sp1 ._lineWidth !=sp2 ._lineWidth )
            {
                return false;
            }
            if (sp2 ._lineColor !=sp1 ._lineColor )
            {
                return false;   
            }
            if (sp1._colorMode != sp2._colorMode)
            {
                return false;
            }


            if (IsListLinearContourColorValueEqual(sp1 ._contourlines ,sp2 ._contourlines )==false )
            {
                return false;
            }
            //if (sp1._contourlines != sp2._contourlines)
            //{
            //    return false;
            //}

            //if (sp1._contourColors != sp2._contourColors)
            //{
            //    return false;
            //}
            if ((sp1 .ContourColors ==null && sp2 .ContourColors !=null )||(sp1 .ContourColors !=null && sp2 .ContourColors ==null ))
            {
                return false;
            }
            if (sp1 !=null && sp2 !=null )
            {
                if (sp1.ContourColors.Count != sp2.ContourColors.Count)
                {
                    return false;
                }
                else
                {
                    for (int i = 0; i < sp1 .ContourColors .Count ; i++)
                    {
                        if (sp1 .ContourColors [i]!=sp2 .ContourColors [i])
                        {
                            return false;
                        }
                    }
                
                }
            }



            if (sp1._contourDisplayType != sp2._contourDisplayType)
            {
                return false;
            }
            if (sp1._contourInterval != sp2._contourInterval)
            {
                return false;
            }
         
            if (sp1._dsMax != sp2._dsMax)
            {
                return false;
            }
            if (sp1._dsMin != sp2._dsMin)
            {
                return false;
            }
            //if (sp1._isShowLegend != sp2._isShowLegend)
            //{
            //    return false;
            //}
            if (sp1._isSpecifyPrecision != sp2._isSpecifyPrecision)
            {
                return false;
            }
            if (sp1._isSpecifyRange != sp2._isSpecifyRange)
            {
                return false;
            }
            //if (sp1._precision != sp2._precision)
            //{
            //    return false;
            //}
            if (sp1._spRangeMax != sp2._spRangeMax)
            {
                return false;
            }
            if (sp1._spRangeMin != sp2._spRangeMin)
            {
                return false;
            }
            if (sp1._transparency != sp2._transparency)
            {
                return false;
            }

            return true;

        }


        public static bool operator !=(DOContour sp1, DOContour sp2)
        {
            return (!(sp1 == sp2));

        }



        /// <summary>
        /// 取得double值的整数部分的长度
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private int GetDecimalLengthInDoubleValue(List<LinearContourColorValue> lines)
        {

            #region 以下的方法不可用，因为涉及到了double的加减等运算，有计算机内部存储数据的原理很容易知道，以下方法是多么的荒谬 哈哈

            //double intValue = Math.Truncate(value);//取得double的整数部分

            //double decimalValue = 0;

            //if (intValue > value)
            //{
            //    decimalValue = intValue - value;

            //}
            //else if (intValue == value)
            //{
            //    return 0;

            //}
            //else 
            //{
            //    decimalValue = value - intValue;

            //}

            ////将小树部分转换成字符串计算长度
            //int strLength = decimalValue.ToString().Trim().Length;//0.0转成string后为 0  长度为1；  0  0.0   0.01   0.12345
            //if (strLength > 2)
            //{
            //    return strLength - 2;
            //}
            //else 
            //{
            //    return 0;

            //}

            #endregion

            //还是使用字符串来进行处理吧

            //value = 0.01;
            //value = 10.0;
            //value = 10;

            //string[] ss = value.ToString().Split('.');

            //int strLen = ss.Length;

            //if (strLen > 1)
            //{
            //    int len = ss[1].Length;

            //    if (len > 6)
            //    {
            //        //最多6位吧，再多也没有太大的意义，而且，double的精度也最多小数点后6位
            //        return 6;
            //    }
            //    return len;
            //}
            //else
            //{               
            //    return 0;
            //}

            if (lines == null)
            {
                return 0;
            }

            int maxNumInInt = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                if (lines [i]==null )
                {
                    continue;
                }

                double value = lines[i].Value;


                double intValue = Math.Truncate(value);//取得double的整数部分

                if (intValue > 0)
                {
                    string[] ss2 = value.ToString().Split('.');
                    int strLen2 = ss2.Length;
                    if (strLen2 > 0)
                    {
                        int len = ss2[0].Length;

                        if (len > 6)
                        {
                            //最多6位吧，再多也没有太大的意义，而且，double的精度也最多小数点后6位
                            return 6;
                        }
                        if (maxNumInInt<len )
                        {
                            maxNumInInt = len;
                        }
                        continue;
                    }
                    else
                    {
                        if (maxNumInInt < 0)
                        {
                            maxNumInInt = 0;
                        }
                    }

                }
                else if (intValue < 0)
                {
                    string[] ss2 = (-value).ToString().Split('.');
                    int strLen2 = ss2.Length;
                    if (strLen2 > 0)
                    {
                        int len = ss2[0].Length;

                        if (len > 6)
                        {
                            //最多6位吧，再多也没有太大的意义，而且，double的精度也最多小数点后6位
                            return 6;
                        }

                        if (maxNumInInt < len)
                        {
                            maxNumInInt = len;
                        }

                        continue;
                    }
                    else
                    {
                        if (maxNumInInt < 0)
                        {
                            maxNumInInt = 0;
                        }
                    }


                }
                else
                {
                    if (maxNumInInt<0)
                    {
                        maxNumInInt = 0;
                    }

                }


            }//for循环结束


            //maxNumInInt记录了整数部分的最大长度
            if (maxNumInInt <=1)
            {
                return 0;
            }
            else
            //(maxNumInInt>1 )
            {
                return maxNumInInt - 1;
            }

            //return maxNumInInt;

        }



        public override void SetIsNeedUpdateDataToFalse()
        {
            base.SetIsNeedUpdateDataToFalse();

            this.isNeedUpdateData = false;

            if (this.ContourLineProperty !=null )
            {
                this.ContourLineProperty.SetIsNeedUpdateDataToFalse();
            }



        }



       /// <summary>
        /// 克隆List<LinearContourColorValue>
       /// </summary>
       /// <param name="newListLinearValue"></param>
       /// <returns></returns>
        protected List<LinearContourColorValue> GetNewListLinearContourColorValue(List<LinearContourColorValue> newListLinearValue)
        {
            if (newListLinearValue==null )
            {
                return null;
            }

            List<LinearContourColorValue> contorLine = new List<LinearContourColorValue>();

            if (newListLinearValue != null)
            {
                for (int i = 0; i < newListLinearValue.Count; i++)
                {
                    if (newListLinearValue[i] != null)
                    {
                        LinearContourColorValue temp = (LinearContourColorValue)newListLinearValue[i].Clone();

                        contorLine.Add(temp);
                    }
                    else
                    {
                        contorLine.Add(null);
                    }

                }

            }
            else
            {
                contorLine = null;
            }


            return contorLine;
           

        }

        /// <summary>
        /// 克隆List<Color>
        /// </summary>
        /// <param name="newListColor"></param>
        /// <returns></returns>
        protected List<System.Drawing.Color> GetNewListColor(List<System.Drawing.Color> newListColor)
        {
            if (newListColor ==null )
            {
                return null;
            }

            List<System.Drawing.Color> temp = new List<System.Drawing.Color>();

            for (int i = 0; i < newListColor .Count ; i++)
            {
                System.Drawing.Color colorTemp = System.Drawing.Color.FromArgb(newListColor [i].A,newListColor [i].R,newListColor [i].G,newListColor [i].B);

                temp.Add(colorTemp );
                //temp.Add(newListColor[i]);
            }

            return temp;


        
        }

        /// <summary>
        /// 相等返回true，否则返回false
        /// </summary>
        /// <param name="linear1"></param>
        /// <param name="linear2"></param>
        /// <returns></returns>
        protected static bool IsListLinearContourColorValueEqual(List<LinearContourColorValue> linear1, List<LinearContourColorValue> linear2)
        {

            if (linear1 ==null && linear2 !=null )
            {
                return false;
            }


            if (linear1 !=null && linear2==null )
            {
                return false;
            }

            if (linear1 !=null && linear2 !=null )
            {

                if (linear1 .Count !=linear2 .Count )
                {
                    return false;
                }

                for (int i = 0; i < linear1 .Count ; i++)
                {
                    if (linear1 [i]!=null && linear2 [i]==null )
                    {
                        return false;
                    }
                    if (linear1 [i]==null && linear2 [i]!=null)
                    {
                        return false;
                    }
                    if (linear1 [i]!=null && linear2 [i]!=null)
                    {
                        if ((linear1 [i].Value !=linear2[i].Value )|| (linear1 [i].Color !=linear2 [i].Color ))
                        {
                            return false;
                        }
                    }

                }

            }


            return true;

        }





        #region ICloneable 成员

        public object Clone()
        {
            DOContour option = (DOContour)this.MemberwiseClone();

            option._contourLineProperty = (DOContourLineProperty)this._contourLineProperty.Clone();

            //值传递
            List<System.Drawing.Color> color = new List<Color>();
            color.AddRange(this.ContourColors);

            option.ContourColors = new List<Color>();
            option.ContourColors = color;



            option._contourlines = new List<LinearContourColorValue>();

            option._contourlines = GetNewListLinearContourColorValue(this._contourlines);



           
            //List <LinearContourColorValue > contorLine=new List<LinearContourColorValue> ();
            //if (this._contourlines != null)
            //{
            //    for (int i = 0; i < this._contourlines.Count; i++)
            //    {
            //        if (this._contourlines[i] != null)
            //        {
            //            LinearContourColorValue temp = (LinearContourColorValue)this._contourlines[i].Clone();
            //            contorLine.Add(temp);
            //        }
            //        else
            //        {
            //            contorLine.Add(null );
            //        }
                   
            //    }
            //}
            //else
            //{
            //    contorLine = null;
            //}
            ////contorLine .AddRange (this ._contourlines );


            //option._contourlines = new List<LinearContourColorValue>();
            //option._contourlines = contorLine;






            return option;


        }





        #endregion

        #region IObjectDataHelper 成员

        public void ResetDataAndTriggerEvent(object obj)
        {
            if (obj == null)
            {
                return;

            }
            DOContour doContour = (DOContour)obj;

            //运算符重载   其根本还是遍历类中的所有字段进行了比较  
            if (doContour.IsDataChanged() == false)
            {
                return;
            }

            //if (this != doContour)
            {

                //赋值部分不应该包括单独走事件更新的数据部分


                List<string> contourPropertyChanges = new List<string>();



                List<string> contourLineValue = new List<string>();

                //this._contourlines = doContour._contourlines;
                ///等值线 List 集合
                if (this._contourlines.Count != doContour._contourlines.Count)
                {
                    //等值线值的变化   走等值线值事件
                    //this._contourlines = doContour._contourlines;
                    //this._contourlines = GetNewListLinearContourColorValue ( doContour._contourlines);

                    contourLineValue.Add(ContourSetupChangedType.ContourLineValueList.ToString());

                }
                else
                {
                    for (int i = 0; i < this._contourlines.Count; i++)
                    {
                        if (this._contourlines[i].Value != doContour._contourlines[i].Value)
                        {
                            //this._contourlines = doContour._contourlines;

                            contourLineValue.Add(ContourSetupChangedType.ContourLineValueList.ToString());

                            break;
                        }
                    }

                    for (int i = 0; i < this._contourlines.Count; i++)
                    {
                        //颜色的变化走   等值线属性变化事件  二维Gis需要 ，因为Value的改变需要重新计算，效率低，而颜色的改变只需要绘制，需要不同处理

                        if ((this._contourlines[i].Color.R != doContour._contourlines[i].Color.R) || (this._contourlines[i].Color.G != doContour._contourlines[i].Color.G) || (this._contourlines[i].Color.B != doContour._contourlines[i].Color.B) || (this._contourlines[i].Color.A != doContour._contourlines[i].Color.A))
                        //if (this._contourlines[i].Color != doContour._contourlines[i].Color)
                        {
                            //this._contourlines = doContour._contourlines;
                            //this._contourlines = GetNewListLinearContourColorValue(doContour._contourlines);

                            contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());

                            break;

                        }

                    }

                }
                //等值线值的变化   走等值线值事件
                if (contourLineValue.Count > 0 || _contourlines.Count > 0)
                {
                    //this._contourlines = doContour._contourlines;
                    this._contourlines = GetNewListLinearContourColorValue(doContour._contourlines);

                }


                if (contourLineValue.Count > 0)
                {
                    contourLineValue.Clear();

                    contourLineValue.Add(ContourSetupChangedType.ContourLineValueList.ToString());

                    this.AskContourSetupChanged(new ContourSetupChangedEventArgs(this, ContourSetupChangedType.ContourLineValueList, contourLineValue));

                }


                #region

                //是否使用单元格的真实数据
                if (_isUseCellRealData !=doContour .IsUseCellRealData )
                {
                    _isUseCellRealData = doContour.IsUseCellRealData;

                    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());     
                }



                //使用小数点位数控制

                if (DecimalDigitNum != doContour.DecimalDigitNum)
                {                 
                    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());       
                }
               
                _isSpecifyPrecision = doContour._isSpecifyPrecision;

                this._specifyPrecisioDecimalNum = doContour._specifyPrecisioDecimalNum;

                this._noSpecifyPrecisionDecimalNum = doContour._noSpecifyPrecisionDecimalNum;


                //是否使用小数点位数控制

                //if (_isSpecifyPrecision!=doContour._isSpecifyPrecision)
                //{
                //    this._isSpecifyPrecision = doContour._isSpecifyPrecision;

                //    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());
                //}

                ////小数点位数   等值线属性变化事件
                //if (_isSpecifyPrecision == false)
                //{
                //    if (this._decimalDigitNum != doContour._decimalDigitNum)
                //    {
                //        this._decimalDigitNum = doContour._decimalDigitNum;

                //    }
                //    if (_noSpecifyPrecisionDecimalNum !=doContour ._noSpecifyPrecisionDecimalNum )
                //    {
                //        this._noSpecifyPrecisionDecimalNum = doContour._noSpecifyPrecisionDecimalNum;

                //        contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());

                //    }
                //}
                //else
                //{

                //    if (this._decimalDigitNum != doContour._decimalDigitNum)
                //    {
                //        this._decimalDigitNum = doContour._decimalDigitNum;

                //        contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());
                //    }

                //    if (_noSpecifyPrecisionDecimalNum != doContour._noSpecifyPrecisionDecimalNum)
                //    {
                //        this._noSpecifyPrecisionDecimalNum = doContour._noSpecifyPrecisionDecimalNum;
                //    }
                //}

                #endregion


                if (_isUseScientificNotation != doContour.IsUseScientificNotation)
                {
                    this._isUseScientificNotation = doContour._isUseScientificNotation;

                    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());

                }

                //等值线属性变化事件

                if (this._contourDisplayType != doContour._contourDisplayType)
                {
                    this._contourDisplayType = doContour._contourDisplayType;

                    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());
                }


                //等值线宽度   线性  线性+填充  模式   等值线属性变化事件

                if (_contourDisplayType != ContourDisplayType.ColorFill)
                {
                    //显示线  需要线宽  现款改变需要通知

                    if (this._lineWidth != doContour._lineWidth)
                    {
                        this._lineWidth = doContour._lineWidth;

                        contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());
                    }
                }
                else
                {
                    //不显示线  不需要通知线宽改变事件
                    if (this._lineWidth != doContour._lineWidth)
                    {
                        this._lineWidth = doContour._lineWidth;
                    }

                }


                //等值线颜色  用于   线性+填充 模式   等值线属性变化事件
                if (_contourDisplayType == ContourDisplayType.LinearAndColorFill)
                {
                    //需要设置的等值线的统一颜色
                    if ((this._lineColor.R != doContour._lineColor.R) || (this._lineColor.G != doContour._lineColor.G) || (this._lineColor.B != doContour._lineColor.B) || (this._lineColor.A != doContour._lineColor.A))
                    //if (this._lineColor != doContour._lineColor)
                    {
                        this._lineColor = doContour.LineColor;
                        contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());

                    }
                }
                else
                {
                    if ((this._lineColor.R != doContour._lineColor.R) || (this._lineColor.G != doContour._lineColor.G) || (this._lineColor.B != doContour._lineColor.B) || (this._lineColor.A != doContour._lineColor.A))
                    //if (this._lineColor != doContour._lineColor)
                    {
                        this._lineColor = doContour.LineColor;
                    }

                }



                //等值线条数
                if (_contourlines != null)
                {
                    this.dataCount = _contourlines.Count;
                }
                else
                {
                    this.dataCount = 0;
                }

                //this.dataCount = doContour.dataCount;





                this._colorMode = doContour._colorMode;

                this._contourColors = GetNewListColor(doContour._contourColors);

                this._contourInterval = doContour._contourInterval;



                this._dsMax = doContour._dsMax;
                this._dsMin = doContour._dsMin;
                //this._isShowLegend = doContour._isShowLegend; 
                this._isSpecifyRange = doContour._isSpecifyRange;
                //this._precision = doContour._precision;
                this._spRangeMax = doContour._spRangeMax;
                this._spRangeMin = doContour._spRangeMin;


                this.dataRange = doContour.dataRange;


                this._transparency = doContour._transparency;







                if (contourPropertyChanges.Count > 0)
                {
                    contourPropertyChanges.Clear();

                    contourPropertyChanges.Add(ContourChangedType.ContourLineProperty.ToString());

                    this.AskContourSetupChanged(new ContourSetupChangedEventArgs(this, ContourSetupChangedType.ContourLine, contourPropertyChanges));

                }






                //if (this.ContourLinesChanged != null)
                //{
                //    this.ContourLinesChanged(this, new EventArgs());

                //}


                //其他数据的更新

                if (this.ContourLineProperty != null)
                {
                    this.ContourLineProperty.ResetDataAndTriggerEvent(doContour.ContourLineProperty);

                }



            }

            //需要判断和旧的等值线是否相等


            //throw new NotImplementedException();
        }

        public bool IsDataChanged( )
        {
            if (this.isNeedUpdateData == true)
            {
                return true;
            }
            else
            {
                if (this.ContourLineProperty != null)
                {
                    if (this.ContourLineProperty.IsDataChanged() == true)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                    
                }
                else
                {
                    return false;
                }
               
            }


            //throw new NotImplementedException();
        }

        #endregion
    }

}
